package com.example.smartcity.ui.Adapter;

import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.cardview.widget.CardView;
import androidx.recyclerview.widget.RecyclerView;

import com.example.smartcity.R;
import com.example.smartcity.ui.Bean.ShopMessageBean;

import java.util.ArrayList;

public class ShopMessageAdapter extends RecyclerView.Adapter<ShopMessageAdapter.MyViewHolder> {
    int Resource;
    private ArrayList<ShopMessageBean> list;
    public ShopMessageAdapter(int Resource, ArrayList<ShopMessageBean> list){
        this.Resource = Resource;
        this.list = list;
    }


    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new MyViewHolder(LayoutInflater.from(parent.getContext()).inflate(Resource,parent,false));
    }

    @Override
    public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
        ShopMessageBean bean = list.get(position);
        holder.CDBackground.setBackgroundColor(Color.parseColor(bean.getBackground()));
        holder.activityMessage.setText(bean.getMessage());
        holder.activityTitle.setText(bean.getTitle());
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    static class MyViewHolder extends RecyclerView.ViewHolder {
        private CardView CDBackground;
        private TextView activityTitle;
        private TextView activityMessage;
        public MyViewHolder(@NonNull View itemView) {
            super(itemView);
            CDBackground = itemView.findViewById(R.id.CD_background);
            activityTitle = itemView.findViewById(R.id.activityTitle);
            activityMessage = itemView.findViewById(R.id.activityMessage);
        }
    }
}
